package collection.list.ArrayList;

import java.util.ArrayList;
import java.util.Iterator;

//ArrayList特有方法
public class Demo {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("A");
        list.add("B");
        list.add("C");
        System.out.println(list);
        //增
        list.add(1,"D");
        System.out.println(list);
        //删
        System.out.println(list.remove(2));
        System.out.println(list);
        //改
        list.set(1,"E");
        System.out.println(list);
        //查
        System.out.println(list.get(1));
        System.out.println("======================");
        //for循环+增强for循环，迭代器、forEach
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println("======================");
        for (String s:list){
            System.out.println(s);
        }
        System.out.println("======================");
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.println(s);
        }
        System.out.println("======================");
        list.forEach(System.out::println);


    }
}